package cn.myframe.service.sys.impl;

import cn.myframe.utils.core.PageUtils;
import cn.myframe.utils.core.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.jcraft.jsch.ChannelShell;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import java.util.Map;

import cn.myframe.dao.sys.SysShellDao;
import cn.myframe.entity.sys.SysShellEntity;
import cn.myframe.service.sys.SysShellService;
import cn.myframe.utils.ShellUtil;

/**
 * 远程服务器
 * 
 * @date 2017-12-09 21:13:45
 */
@Service("sysShellService")
public class SysShellServiceImpl implements SysShellService {
	@Autowired
	private SysShellDao sysShellDao;
	
	@Override
	public PageUtils queryPage(Query query) {
		Page<Object> page = PageUtils.getPage(query);
		List<SysShellEntity> list = null;
		if(page != null){
			 list = sysShellDao.queryList(page,query);
		}
		return new PageUtils(list, page.getTotal(), query.getLimit(), query.getPage());
	}
	
	@Override
	public SysShellEntity queryObject(Long id){
		return sysShellDao.queryObject(id);
	}
	
	@Override
	public List<SysShellEntity> queryList(Map<String, Object> map){
		return sysShellDao.queryList(map);
	}
	
	@Override
	public int queryTotal(Map<String, Object> map){
		return sysShellDao.queryTotal(map);
	}
	
	@Override
	@Transactional(rollbackFor = Exception.class)
	public void save(SysShellEntity sysShell){
		sysShellDao.save(sysShell);
	}
	
	@Override
	@Transactional(rollbackFor = Exception.class)
	public void update(SysShellEntity sysShell){
		sysShellDao.update(sysShell);
	}
	
	@Override
	@Transactional(rollbackFor = Exception.class)
	public void delete(Long id){
		sysShellDao.delete(id);
	}
	
	@Override
	@Transactional(rollbackFor = Exception.class)
	public void deleteBatch(Long[] ids){
		sysShellDao.deleteBatch(ids);
	}
	
	@Override
	public int checkExist(String id, String name) {
		return sysShellDao.checkExist(id, name);
	}
	
	@Override
	@CacheEvict(value="shell",allEntries=true)
	public int updateStatus(Long[] ids, Integer status) {
		return sysShellDao.updateStatus(ids, status);
	}

	@Override
	@Cacheable(value="shell",key="'uc_'+#userId+'_'+#shellId")
	public ChannelShell send(Long userId, Long shellId) {
		SysShellEntity shell = queryObject(shellId);
		ChannelShell channel = ShellUtil.getShellChannel(shell.getUserName(), shell.getIp(), shell.getPort(), shell.getPassword());
		return channel;
	}

	@Override
	public void deleteAll() {
		sysShellDao.deleteAll();
		
	}

	@Override
	public Integer queryByIp(String ip) {
		
		return sysShellDao.queryByIp(ip);
	}

	@Override
	public List<SysShellEntity> selectAds() {
		
		return sysShellDao.selectAds();
	}

	@Override
	public void deleteByIp(String ip) {
		sysShellDao.deleteByIp(ip);
		
	}

	@Override
	public SysShellEntity queryObject(Serializable id) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void updateStatus(Long[] ids, Serializable status) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public int checkExist(Serializable id, String name, String columnName) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public boolean insert(SysShellEntity entity) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean insertAllColumn(SysShellEntity entity) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean insertBatch(List<SysShellEntity> entityList) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean insertBatch(List<SysShellEntity> entityList, int batchSize) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean insertOrUpdateBatch(List<SysShellEntity> entityList) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean insertOrUpdateBatch(List<SysShellEntity> entityList, int batchSize) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean insertOrUpdateAllColumnBatch(List<SysShellEntity> entityList) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean insertOrUpdateAllColumnBatch(List<SysShellEntity> entityList, int batchSize) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean deleteById(Serializable id) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean deleteByMap(Map<String, Object> columnMap) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean delete(Wrapper<SysShellEntity> wrapper) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean deleteBatchIds(Collection<? extends Serializable> idList) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean updateById(SysShellEntity entity) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean updateAllColumnById(SysShellEntity entity) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean update(SysShellEntity entity, Wrapper<SysShellEntity> wrapper) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean updateBatchById(List<SysShellEntity> entityList) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean updateBatchById(List<SysShellEntity> entityList, int batchSize) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean updateAllColumnBatchById(List<SysShellEntity> entityList) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean updateAllColumnBatchById(List<SysShellEntity> entityList, int batchSize) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean insertOrUpdate(SysShellEntity entity) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean insertOrUpdateAllColumn(SysShellEntity entity) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public SysShellEntity selectById(Serializable id) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<SysShellEntity> selectBatchIds(Collection<? extends Serializable> idList) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<SysShellEntity> selectByMap(Map<String, Object> columnMap) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public SysShellEntity selectOne(Wrapper<SysShellEntity> wrapper) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Map<String, Object> selectMap(Wrapper<SysShellEntity> wrapper) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object selectObj(Wrapper<SysShellEntity> wrapper) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int selectCount(Wrapper<SysShellEntity> wrapper) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public List<SysShellEntity> selectList(Wrapper<SysShellEntity> wrapper) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Page<SysShellEntity> selectPage(Page<SysShellEntity> page) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<Map<String, Object>> selectMaps(Wrapper<SysShellEntity> wrapper) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<Object> selectObjs(Wrapper<SysShellEntity> wrapper) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Page<Map<String, Object>> selectMapsPage(Page page, Wrapper<SysShellEntity> wrapper) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Page<SysShellEntity> selectPage(Page<SysShellEntity> page, Wrapper<SysShellEntity> wrapper) {
		// TODO Auto-generated method stub
		return null;
	}

	
}
